﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
''' <summary>
''' 进入点,控制整个流程
''' </summary>
''' <remarks></remarks>
<Serializable()> Public Class Bpipprm
    Implements ICloneable

    <NonSerialized()> Private DosCommandOutput As DosCommand.DosCommandOutput '执行Dos程序类
    Private m_Title As String = "Aermod BPIPPRM" '标题
    Private m_Process As String = "P" '处理过程
    Private m_UntisName As String = "METER" '单位名称
    Private m_UntisValue As Double = 1.0 '单位数值
    Private m_GridName As String = "UTMY" ' 坐标处理标志
    Private m_GridVale As Double = 0.0 '坐标处理标志的值

    Private m_ArryBldgi(-1) As CAermod.Bldgi '建筑物
    Private m_ArryBuStack(-1) As CAermod.BuStack '污染源数据

    Private m_No As Integer

    ''' <summary>
    ''' 标题
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Title() As String
        Get
            Return m_Title
        End Get
        Set(ByVal value As String)
            m_Title = value
        End Set
    End Property
    ''' <summary>
    ''' 处理过程
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Process() As String
        Get
            Return m_Process
        End Get
        Set(ByVal value As String)
            m_Process = value
        End Set
    End Property
    ''' <summary>
    ''' 单位名称
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property UntisName() As String
        Get
            Return m_UntisName
        End Get
        Set(ByVal value As String)
            m_UntisName = value
        End Set
    End Property
    ''' <summary>
    ''' 单位数值
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property UntisVale() As Double
        Get
            Return m_UntisValue
        End Get
        Set(ByVal value As Double)
            m_UntisValue = value
        End Set
    End Property
    ''' <summary>
    ''' 坐标处理标志
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property GridName() As String
        Get
            Return m_GridName
        End Get
        Set(ByVal value As String)
            m_GridName = value
        End Set
    End Property
    ''' <summary>
    ''' 坐标处理标志的值
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property GridVale() As Double
        Get
            Return m_GridVale
        End Get
        Set(ByVal value As Double)
            m_GridVale = value
        End Set
    End Property
    ''' <summary>
    ''' 建筑物个数
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property No() As Integer
        Get
            Return Me.m_No
        End Get
        Set(ByVal value As Integer)
            Me.m_No = value
        End Set
    End Property

    ''' <summary>
    ''' 建筑物个数
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArryBldgi() As CAermod.Bldgi()
        Get
            Return m_ArryBldgi
        End Get
        Set(ByVal value As CAermod.Bldgi())
            m_ArryBldgi = value
        End Set
    End Property
    ''' <summary>
    ''' 污染源数据
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArryBuStack() As CAermod.BuStack()
        Get
            Return m_ArryBuStack
        End Get
        Set(ByVal value As CAermod.BuStack())
            m_ArryBuStack = value
        End Set
    End Property
    Public Sub RemoveFormID(ByVal ID As String)
        For j As Integer = 0 To Me.m_ArryBldgi.Length - 1
            If ID = Me.m_ArryBldgi(j).BuildStack Then
                Me.RemoveFormIndex(j)
                Exit For
            End If
        Next
    End Sub
    ''' <summary>
    ''' 删除对应的关心点
    ''' </summary>
    ''' <param name="Index"></param>
    ''' <remarks></remarks>
    Public Sub RemoveFormIndex(ByVal Index As Integer)
        Dim iSelected As Integer = Index
        If iSelected >= 0 Then
            If iSelected <= Me.m_ArryBldgi.Length - 2 Then
                For i As Integer = iSelected To Me.m_ArryBldgi.Length - 2
                    Me.m_ArryBldgi(i) = Me.m_ArryBldgi(i + 1)
                Next
            End If
            ReDim Preserve Me.m_ArryBldgi(Me.m_ArryBldgi.Length - 2)
        End If
    End Sub
    ''' <summary>
    ''' 返回建筑物下洗的字符串
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function OutPutBp() As String
        Dim strB As String = ""
        strB += "'" & Me.m_Title & "'" & vbCrLf
        strB += "'" & Me.m_Process & "'" & vbCrLf
        strB += "'" & Me.m_UntisName & "' " & Me.m_UntisValue & vbCrLf
        strB += "'" & Me.m_GridName & "' " & Me.m_GridVale & vbCrLf
        strB += Me.ArryBldgi.Length & vbCrLf
        For i As Integer = 0 To Me.ArryBldgi.Length - 1
            strB += Me.ArryBldgi(i).OutBldgi()
        Next
        strB += m_ArryBuStack.Length & vbCrLf
        For i As Integer = 0 To Me.ArryBuStack.Length - 1
            strB += ArryBuStack(i).OutBuStack()
        Next
        strB += "0" & vbCrLf
        Return strB
    End Function
    ''' <summary>
    ''' 结果的处理，字符串
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function showStr(ByVal PrjFileName As String) As String
        Dim PrjPath As String = My.Computer.FileSystem.GetFileInfo(PrjFileName).DirectoryName
        Dim strNameLast As String = CAermod.GetFileName(PrjFileName)

        For j As Integer = 0 To Me.m_ArryBuStack.Length - 1
            Me.m_ArryBuStack(j).Result = ""
        Next
        Dim Str As String = ""
        If My.Computer.FileSystem.FileExists(PrjPath & "\" & strNameLast & "\" & "bpipprm.out") And My.Computer.FileSystem.FileExists(PrjPath & "\" & strNameLast & "\" & "bpipprm.sum") Then
            Dim pathh As String = PrjPath & "\" & strNameLast & "\" & "bpipprm.out"
            Dim IsBusy As Boolean = True
            Dim filestrea As New FileStream(pathh, FileMode.Open)
            Dim StrRead As New StreamReader(filestrea)
            Dim a As String = ""
            Dim i As Integer = 0
            Do
                a = StrRead.ReadLine()
                If a.Contains("SO ") Then
                    Dim strA As String = a.TrimStart("     ")
                    For j As Integer = 0 To Me.m_ArryBuStack.Length - 1
                        If strA.Contains(Me.m_ArryBuStack(j).BrandName) Then
                            Me.m_ArryBuStack(j).Result += strA & vbCrLf
                        End If
                    Next
                End If
            Loop While StrRead.Peek <> -1
            StrRead.Close()
            filestrea.Close()
        End If
        For j As Integer = 0 To Me.m_ArryBuStack.Length - 1
            Str += Me.m_ArryBuStack(j).Result
        Next
        Return Str
    End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj As New Bpipprm
        obj.m_Title = Me.m_Title '标题
        obj.m_Process = Me.m_Process  '处理过程
        obj.m_UntisName = Me.m_UntisName  '单位名称
        obj.m_UntisValue = Me.m_UntisValue  '单位数值
        obj.m_GridName = Me.m_GridName ' 坐标处理标志
        obj.m_GridVale = Me.m_GridVale  '坐标处理标志的值
        ReDim obj.m_ArryBldgi(Me.m_ArryBldgi.Length - 1)
        For i As Integer = 0 To Me.m_ArryBldgi.Length - 1
            obj.m_ArryBldgi(i) = Me.m_ArryBldgi(i).Clone
        Next
        ReDim obj.m_ArryBuStack(Me.m_ArryBuStack.Length - 1)
        For i As Integer = 0 To Me.m_ArryBuStack.Length - 1
            obj.m_ArryBuStack(i) = Me.m_ArryBuStack(i).Clone
        Next
        obj.m_No = Me.m_No
        Return obj
    End Function

    <OnDeserializing()> _
Friend Sub OnDeserializingMethod(ByVal context As StreamingContext)

    End Sub

    <OnDeserialized()> _
    Friend Sub OnDeserializedMethod(ByVal context As StreamingContext)
        If Me.m_No = Nothing Or Me.m_No = 0 Then
            Me.m_No = Me.ArryBldgi.Length
        End If
    End Sub

End Class
